<div class="content-wrapper">
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dbshop-menu-top">
            <a href="<?php echo $this->url('template', ['action' => 'installMobileTemplate']) ?>" class="btn btn-primary btn-sm"><i class="fa fa-cloud-download" aria-hidden="true"></i> <?php echo $this->translate('在线安装模板'); ?></a>
            <?php echo $this->HelpUrl('template'); ?>
        </h1>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li><a href="<?php echo $this->url('template'); ?>"><?php echo $this->translate('电脑端模板'); ?></a></li>
                        <li class="active"><a href=""><?php echo $this->translate('手机端模板'); ?></a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="box-body">
                                <?php echo $this->partial('layout/messages'); ?>

                                <?php if ($this->templateArray) { foreach ($this->templateArray as $templateValue) { ?>
                                    <div class="col-lg-4" style="border: 1px solid #e3e3e3;">
                                        <?php if (isset($this->updateTemplate[$templateValue['templateCode']]) && $this->updateTemplate[$templateValue['templateCode']] > $templateValue['versionNumber']) { ?>
                                            <div class="template-update bg-red">
                                                <?php echo $this->translate('模板有新的更新'); ?>
                                                <button type="button" onclick="installTemplate('<?php echo $templateValue['templateCode']; ?>');" class="btn btn-xs btn-primary"><?php echo $this->translate('点击更新'); ?></button>
                                            </div>
                                        <?php } ?>

                                        <img src="<?php echo $this->basePath('./template/'.str_replace('-', '/', $templateValue['templateCode']).'/template.png'); ?>" class="img-responsive pad">
                                        <div class="well row" style="margin-bottom: unset;border-radius: unset;border: 0;padding: 10px;">
                                            <div class="col-md-4">
                                                <strong style="font-size: 16px;"><?php echo $this->escapeHtml($templateValue['templateName']); ?></strong>
                                            </div>
                                            <div class="col-md-8 text-right">
                                                <?php if (isset($templateValue['enable'])) { ?>
                                                    <a href="javascript:;" class="btn btn-success btn-sm"><i class="fa fa-mobile fa-lg" aria-hidden="true"></i> <?php echo $this->translate('已启用'); ?></a>
                                                <?php } else { ?>
                                                    <a href="<?php echo $this->url('template', ['action' => 'changeShopTemplate'], ['query' => ['templateCode' => $templateValue['templateCode']]]) ?>" class="btn btn-primary btn-sm"><i class="fa fa-crosshairs" aria-hidden="true"></i> <?php echo $this->translate('点击启用'); ?></a>
                                                <?php } ?>
                                                <a href="<?php echo $templateValue['helpDocumentUrl']; ?>" target="_blank" class="btn btn-info btn-sm" title="<?php echo $this->translate('点击查看教程'); ?>"><i class="fa fa-book" aria-hidden="true"></i></a>
                                                <button  onclick="installTemplate('<?php echo $templateValue['templateCode']; ?>');" class="btn btn-warning btn-sm" title="<?php echo $this->translate('点击重装'); ?>"><i class="fa fa-refresh" aria-hidden="true"></i></button>
                                            </div>
                                            <small class="col-md-12" style="padding-top: 5px;"><span class="text-bold"><?php echo $this->translate('支持语言'); ?>：</span><?php if (isset($this->templateLanguage[$templateValue['templateCode']]) && !empty($this->templateLanguage[$templateValue['templateCode']])) echo $this->escapeHtml($this->templateLanguage[$templateValue['templateCode']]); else echo '简体中文、繁体中文、英文、日文、韩文';  ?></small>
                                        </div>
                                    </div>
                                <?php } } else { ?>
                                    <p class="text-bold text-red"><?php echo $this->translate('还没有安装手机模板，点击去安装第一个手机模板吧!'); ?> <a href="<?php echo $this->url('template', ['action' => 'installMobileTemplate']) ?>" class="btn btn-sm btn-primary"><i class="fa fa-cloud-download" aria-hidden="true"></i> <?php echo $this->translate('点击安装'); ?></a></p>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<?php if ($this->templateArray) { ?>
    <script type="text/javascript">
        function installTemplate(templateCode) {
            layer.confirm('<?php echo $this->translate('安装时会覆盖当前模板文件，如果您对模板源文件有所修改，请提前做好备份。现在要进行安装吗？'); ?>', {icon: 0, title:'<?php echo $this->translate('安装提示'); ?>', btn:['<?php echo $this->translate('点击马上安装'); ?>', '<?php echo $this->translate('稍后再安装'); ?>']}, function () {
                layer.msg('<?php echo $this->translate('正在安装模板……，请不要关闭页面'); ?>', {
                    icon: 16
                    ,shade: 0.01
                    ,time: 300000
                });
                $.post("<?php echo $this->url('template', ['action' => 'startInstallTemplate']) ?>", {templateCode:templateCode}, function (data) {
                    if (data.state == 'false') {
                        layer.alert(data.message, {title: '<?php echo $this->translate('错误提示'); ?>', area:['50%', '70%']});
                        return false;
                    }
                    shopMessage(data.message);
                    window.location.reload();
                }, 'json');
            });
        }
    </script>
<?php } ?>